package api

import (
	"feng-che.com/server/driver-quiz/internal/sysLogger"
	"github.com/gofiber/fiber/v2"
	"github.com/sirupsen/logrus"
	"os"
)

func Route(app *fiber.App) {
	env := os.Getenv("ENV")
	var api fiber.Router
	if env == "Localhost" {
		api = app.Group("/api", func(c *fiber.Ctx) error {
			body := string(c.Body())
			sysLogger.SysLog.WithFields(logrus.Fields{
				"body":   body,
				"Method": c.Method(),
				"path":   c.Path(),
				"ip":     c.IP(),
			}).Info("request")
			return c.Next()
		})
	} else {
		api = app.Group("/api", func(c *fiber.Ctx) error {
			return c.Next()
		})
	}

	installAdmin(api.Group("/admin"))
	userInMobile(api.Group("/userMobile"))
	superAdmin(api.Group("/superAdmin"))
	installClientRouter(api.Group("/client"))
	installWeixinRouter(api.Group("/weixin"))
	installPartnerRouter(api.Group("/partner"))
	installCommonRouter(api.Group("/common"))
}
